package com.boyadegroot.divelog.models;

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;

public class Dive implements Parcelable, Comparable<Dive> {

    private static final String TAG = Dive.class.getName();

    private long mId;
    private long mStartTime;
    private int mDuration; // (s)
    private DiveSite mSite;
    private Diver mDiver;
    private int mSurfaceInterval; // (s)
    private double mMaxDepth; // (m)
    private double mAvgDepth; // (m)
    private int mAirTemp; // (°C)
    private int mSurfaceTemp; // (°C)
    private int mBottomTemp; // (°C)
    private int mTankVolume; // (l)
    private int mStartPressure; // (bar)
    private int mEndPressure; // (bar)
    private double mWeight; // (kg)
    private int mO2Percentage; // (%)
    private DiveBuddy mBuddy;
    private DiveTrip mTrip;
    private String mLogNotes;

    public Dive() {}

    public Dive(long id, long startTime, int duration, DiveSite site, Diver diver,
                int surfaceInterval, double maxDepth, double avgDepth, int airTemp, int surfaceTemp,
                int bottomTemp, int tankVolume, int startPressure, int endPressure, double weight,
                int o2Percentage, DiveBuddy buddy, DiveTrip trip, String logNotes) {
        this.setId(id);
        this.setStartTime(startTime);
        this.setDuration(duration);
        this.setSite(site);
        this.setDiver(diver);
        this.setSurfaceInterval(surfaceInterval);
        this.setMaxDepth(maxDepth);
        this.setAvgDepth(avgDepth);
        this.setAirTemp(airTemp);
        this.setSurfaceTemp(surfaceTemp);
        this.setBottomTemp(bottomTemp);
        this.setTankVolume(tankVolume);
        this.setStartPressure(startPressure);
        this.setEndpressure(endPressure);
        this.setWeight(weight);
        this.setO2Percentage(o2Percentage);
        this.setBuddy(buddy);
        this.setTrip(trip);
        this.setLogNotes(logNotes);
    }

    public long getId() {
        return mId;
    }

    public void setId(long id) {
        this.mId = id;
    }

    public long getStartTime() {
        return mStartTime;
    }
    
    public void setStartTime(long startTime) {
        this.mStartTime = startTime;
    }
    
    public int getDuration() {
        return mDuration;
    }
    
    public void setDuration(int duration) {
        this.mDuration = duration;
    }
    
    public DiveSite getSite() {
        return mSite;
    }
    
    public void setSite(DiveSite site) {
        this.mSite = site;
    }
    
    public Diver getDiver() {
        return mDiver;
    }
    
    public void setDiver(Diver diver) {
        this.mDiver = diver;
    }
    
    public int getSurfaceInterval() {
        return mSurfaceInterval;
    }
    
    public void setSurfaceInterval(int surfaceInterval) {
        this.mSurfaceInterval = surfaceInterval;
    }
    
    public double getMaxDepth() {
        return mMaxDepth;
    }
    
    public void setMaxDepth(double maxDepth) {
        this.mMaxDepth = maxDepth;
    }
    
    public double getAvgDepth() {
        return mAvgDepth;
    }
    
    public void setAvgDepth(double avgDepth) {
        this.mAvgDepth = avgDepth;
    }
    
    public int getAirTemp() {
        return mAirTemp;
    }
    
    public void setAirTemp(int airTemp) {
        this.mAirTemp = airTemp;
    }
    
    public int getSurfaceTemp() {
        return mSurfaceTemp;
    }
    
    public void setSurfaceTemp(int surfaceTemp) {
        this.mSurfaceTemp = surfaceTemp;
    }
    
    public int getBottomTemp() {
        return mBottomTemp;
    }
    
    public void setBottomTemp(int bottomTemp) {
        this.mBottomTemp = bottomTemp;
    }
    
    public int getTankVolume() {
        return mTankVolume;
    }
    
    public void setTankVolume(int tankVolume) {
        this.mTankVolume = tankVolume;
    }
    
    public int getStartPressure() {
        return mStartPressure;
    }
    
    public void setStartPressure(int startPressure) {
        this.mStartPressure = startPressure;
    }
    
    public int getEndpressure() {
        return mEndPressure;
    }
    
    public void setEndpressure(int endPressure) {
        this.mEndPressure = endPressure;
    }
    
    public double getWeight() {
        return mWeight;
    }
    
    public void setWeight(double weight) {
        this.mWeight = weight;
    }
    
    public int getO2Percentage() {
        return mO2Percentage;
    }
    
    public void setO2Percentage(int o2Percentage) {
        this.mO2Percentage = o2Percentage;
    }
    
    public DiveBuddy getBuddy() {
        return mBuddy;
    }
    
    public void setBuddy(DiveBuddy buddy) {
        this.mBuddy = buddy;
    }
    
    public DiveTrip getTrip() {
        return mTrip;
    }
    
    public void setTrip(DiveTrip trip) {
        this.mTrip = trip;
    }

    public String getLogNotes() {
        return mLogNotes;
    }

    public void setLogNotes(String logNotes) {
        mLogNotes = logNotes;
    }

    @Override
    public int compareTo(@NonNull Dive another) {
        return ((Long) this.mStartTime).compareTo(another.mStartTime);
    }

    @Override
    public String toString() {
        return getSite().toString();
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeLong(mId);
        dest.writeLong(mStartTime);
        dest.writeInt(mDuration);
        dest.writeParcelable(mSite, flags);
        dest.writeParcelable(mDiver, flags);
        dest.writeInt(mSurfaceInterval);
        dest.writeDouble(mMaxDepth);
        dest.writeDouble(mAvgDepth);
        dest.writeInt(mAirTemp);
        dest.writeInt(mSurfaceTemp);
        dest.writeInt(mBottomTemp);
        dest.writeInt(mTankVolume);
        dest.writeInt(mStartPressure);
        dest.writeInt(mEndPressure);
        dest.writeDouble(mWeight);
        dest.writeInt(mO2Percentage);
        dest.writeParcelable(mBuddy, flags);
        dest.writeParcelable(mTrip, flags);
        dest.writeString(mLogNotes);
    }

    public static final Parcelable.Creator<Dive> CREATOR = new Parcelable.Creator<Dive>() {

        public Dive createFromParcel(Parcel in) {
            return new Dive(in);
        }

        public Dive[] newArray(int size) {
            return new Dive[size];
        }
    };

    private Dive(Parcel in) {
        mId = in.readLong();
        mStartTime = in.readLong();
        mDuration = in.readInt();
        mSite = in.readParcelable(DiveSite.class.getClassLoader());
        mDiver = in.readParcelable(Diver.class.getClassLoader());
        mSurfaceInterval = in.readInt();
        mMaxDepth = in.readDouble();
        mAvgDepth = in.readDouble();
        mAirTemp = in.readInt();
        mSurfaceTemp = in.readInt();
        mBottomTemp = in.readInt();
        mTankVolume = in.readInt();
        mStartPressure = in.readInt();
        mEndPressure = in.readInt();
        mWeight = in.readDouble();
        mO2Percentage = in.readInt();
        mBuddy = in.readParcelable(DiveBuddy.class.getClassLoader());
        mTrip = in.readParcelable(DiveTrip.class.getClassLoader());
        mLogNotes = in.readString();
    }
}
